-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Serve] Handle multiple changed objects per LongPollHost.listen_for_change
RPC
#48803
Merged
edoakes
merged 2 commits into
ray-project:master
from
JoshKarpel:handle-multiple-updated-keys-in-long-poll-host
Nov 19, 2024
Merged
[Serve] Handle multiple changed objects per LongPollHost.listen_for_change
RPC
#48803
edoakes
merged 2 commits into
ray-project:master
from
JoshKarpel:handle-multiple-updated-keys-in-long-poll-host
Nov 19, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Josh Karpel <josh.karpel@gmail.com>
JoshKarpel
force-pushed
the
handle-multiple-updated-keys-in-long-poll-host
branch
from
November 19, 2024 17:05
2dcc0fb
to
89cf841
Compare
edoakes
approved these changes
Nov 19, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
JoshKarpel
deleted the
handle-multiple-updated-keys-in-long-poll-host
branch
November 20, 2024 02:36
dentiny
pushed a commit
to dentiny/ray
that referenced
this pull request
Dec 7, 2024
…change` RPC (ray-project#48803) <!-- Thank you for your contribution! Please review https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? Currently, in the `LongPollHost`/`LongPollClient`, if multiple objects are updated that a `listen_for_change` request is waiting for *before the async task in the host can run again*, only one of those updated objects will be returned. This is inefficient because the `LongPollClient` will immediately do a `listen_for_change` RPC again, and that will see outdated snapshot IDs for the updates that weren't returned and get all of the missed updates. This is because of an asymmetry between https://github.com/ray-project/ray/blob/b75cb793e437aa617d61dcb13e5f5d2fcc83ee68/python/ray/serve/_private/long_poll.py#L252-L272 , which looks for *all* outdated keys, and https://github.com/ray-project/ray/blob/b75cb793e437aa617d61dcb13e5f5d2fcc83ee68/python/ray/serve/_private/long_poll.py#L309 , which only looks at a single complete `Event`, even if multiple events completed during the [`wait`](https://github.com/ray-project/ray/blob/b75cb793e437aa617d61dcb13e5f5d2fcc83ee68/python/ray/serve/_private/long_poll.py#L289-L293). To prove that the `wait` can indeed see multiple completed `Event`s, see this example: ```python from asyncio import wait, Event, run, create_task, FIRST_COMPLETED async def main(): a = Event() b = Event() wait_for_a = create_task(a.wait()) wait_for_b = create_task(b.wait()) a.set() b.set() done, pending = await wait([wait_for_a, wait_for_b], return_when=FIRST_COMPLETED) print(f"{len(done)=}") print(f"{len(pending)=}") run(main()) # len(done)=2 # len(pending)=0 ``` Generally this won't be a big issue because most `listen_for_change` requests in the current Serve setup are asking for a very small number of keys and are likely to only get one key update anyway. But, as I've been discussing with @edoakes and @zcin on Slack, I'd like to group up the `DeploymentHandle` `listen_for_change` RPCs under a single `LongPollClient`, which will be requesting many keys and is therefore more likely to hit this situation. To complement this change, I also changed `LongPollHost.notify_changed` so that it takes multiple updates at the same time. ## Related issue number <!-- For example: "Closes ray-project#1234" --> ## Checks - [x] I've signed off every commit(by using the -s flag, i.e., `git commit -s`) in this PR. - [x] I've run `scripts/format.sh` to lint the changes in this PR. - [ ] I've included any doc changes needed for https://docs.ray.io/en/master/. - [ ] I've added any new APIs to the API Reference. For example, if I added a method in Tune, I've added it in `doc/source/tune/api/` under the corresponding `.rst` file. - [x] I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/ - Testing Strategy - [x] Unit tests - [ ] Release tests - [ ] This PR is not tested :( --------- Signed-off-by: Josh Karpel <josh.karpel@gmail.com> Signed-off-by: hjiang <dentinyhao@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why are these changes needed?
Currently, in the
LongPollHost
/LongPollClient
, if multiple objects are updated that alisten_for_change
request is waiting for before the async task in the host can run again, only one of those updated objects will be returned. This is inefficient because theLongPollClient
will immediately do alisten_for_change
RPC again, and that will see outdated snapshot IDs for the updates that weren't returned and get all of the missed updates.This is because of an asymmetry between
ray/python/ray/serve/_private/long_poll.py
Lines 252 to 272 in b75cb79
ray/python/ray/serve/_private/long_poll.py
Line 309 in b75cb79
Event
, even if multiple events completed during thewait
.To prove that the
wait
can indeed see multiple completedEvent
s, see this example:Generally this won't be a big issue because most
listen_for_change
requests in the current Serve setup are asking for a very small number of keys and are likely to only get one key update anyway. But, as I've been discussing with @edoakes and @zcin on Slack, I'd like to group up theDeploymentHandle
listen_for_change
RPCs under a singleLongPollClient
, which will be requesting many keys and is therefore more likely to hit this situation.To complement this change, I also changed
LongPollHost.notify_changed
so that it takes multiple updates at the same time.Related issue number
Checks
git commit -s
) in this PR.scripts/format.sh
to lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/
under thecorresponding
.rst
file.